//
//  MoreViewController.m
//  GuoBang
//
//  Created by fengshuai on 16/4/28.
//  Copyright © 2016年 梧桐树. All rights reserved.
//

#import "MoreViewController.h"
#import "QuitTableViewCell.h"
#import "FriendViewController.h"
#import "GuanYuViewController.h"
#import "LoginViewController.h"

@interface MoreViewController ()<UITableViewDataSource, UITableViewDelegate>
{
    QuitTableViewCell *quitCell;
}

@property (nonatomic, strong) UITableView *setTableView;
@property (nonatomic, strong) NSArray *titleArr;
@end

@implementation MoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNVA];
    [self setupUI];
    [self setupData];
    
    
}
- (void)setupNVA
{
    self.title=@"更多";
    //设置返回按键
    //返回按键颜色
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    //返回按键图标
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                         forBarMetrics:UIBarMetricsDefault];
}

- (void)leftAction:(UIBarButtonItem *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setupData
{
    self.titleArr = @[@"使用帮助", @"关于", @"扫码下载", @"给小秘打打分"];

}

- (void)setupUI
{
    
    self.setTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT ) style:UITableViewStyleGrouped];
    self.setTableView.delegate = self;
    self.setTableView.dataSource = self;
    [self.setTableView setScrollEnabled:NO];
    [self.view addSubview:self.setTableView];

    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (section == 2) {
        return 1;
    }
    
    return 2;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cell_id = @"cell_id";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cell_id];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_id];
    }
    
    if (indexPath.section == 0) {
        
        
        cell.textLabel.text = self.titleArr[indexPath.row];
        cell.textLabel.font = [UIFont systemFontOfSize:14];
        cell.textLabel.textColor = RGBCOLOR(69, 69, 69);
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
        
    }else if (indexPath.section == 1) {
        
        
         cell.textLabel.text = self.titleArr[indexPath.row + 2];
        cell.textLabel.font = [UIFont systemFontOfSize:14];
        cell.textLabel.textColor = RGBCOLOR(69, 69, 69);
          cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        return cell;
    }
  
    

    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"QuitTableViewCell" owner:self options:nil];
    if (nib.count > 0) {
        quitCell = [nib objectAtIndex:0];
        [quitCell.quitBtn addTarget:self action:@selector(quitAction:) forControlEvents:UIControlEventTouchUpInside];
        
        cell = quitCell;
    }

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 0) {
        switch (indexPath.row) {
            case 0:
            {
//                LoginViewController *logVC = [LoginViewController new];
//                [self.navigationController pushViewController:logVC animated:YES];
                
            }
                break;
            case 1:
            {
       
                GuanYuViewController *guanYuVC = [GuanYuViewController new];
                [self.navigationController pushViewController:guanYuVC animated:YES];
                
            }
                break;
   
            default:
                break;
        }
    }else {
        switch (indexPath.row) {
            case 0:
            {
                FriendViewController *friVC = [FriendViewController new];
                [self.navigationController pushViewController:friVC animated:YES];
                
            }
                NSLog(@"111111111");
                break;
            case 1:
            {
          
            }
                break;
       
            default:
                break;
        }
        
    }
}





-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 2) {
        return 30;
    }
    
    
    return 15;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}


- (void)quitAction:(UIButton *)sender
{
    UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:[LoginViewController new]];
    
    //设置navbar字体颜色
    [nav.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]];
    //设置navbar背景色
    nav.navigationBar.barTintColor=[SEATools stringToColor:@"ff6d6d"];

    [UIApplication sharedApplication].keyWindow.rootViewController=nav;
    
    
    
}


- (void)rightAction
{
    
}
- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}

@end
